This is a sample Lens Studio project that demonstrates how to implement simple but realistic throwing mechanic in Lens Studio based on physics. It showcases a clean, componentized architecture that takes advantage of the new Hand Velocity API. By exploring the ThrowLab project, you’ll gain a practical understanding of implementing realistic throwing mechanics in AR. This foundation will help you build more engaging and interactive Lens Studio lenses.
NOTE: This project will only work for the Spectacles platform.
Designing Lenses for Spectacles offers all-new possibilities to rethink user interaction with digital spaces and the physical world. Get started using our Design Guidelines
- Lens Studio: v5.10.0+
- Spectacles OS Version: v5.62+
- Spectacles App iOS: v0.62+
- Spectacles App Android: v0.62+
To update your Spectacles device and mobile app, refer to this guide.
You can download the latest version of Lens Studio from here.
This API gives an easy and reliable way of getting the velocity of hand joints as vec3s in world coordinate system.
The API can be used together with SIK:
let handInputData = SIK.HandInputData;
let hand = this.handInputData.getHand('right');
let objectSpecificData = this.hand.objectTracking3D.objectSpecificData
if (objectSpecificData) {
let handVelocity = objectSpecificData['global'];
let indexVelocity = objectSpecificData['index-3'];
}
The following joints are available for the velocities: “index-3”, “mid-3”, “ring-3”, “pinky-3”, “thumb-3” and “global”.
With ThrowLab, you can pinch to grab, and then throw four different objects. We have 2 example objects in the project:
Each object has slightly different behaviors and corresponding sounds on collision. Dart is a more complex example with some specific logic for hitting the dart board.
-
Hand Detection & Velocity Calculation:
Lens Studio’s Hand Tracking system detects your hand. As you move, the Hand Velocity API provides the velocity of the relevant joints. -
Object Selection & Holding
ThrowLab uses a pinch gesture provided by the Spectacles Interaction Kit (SIK) to allow the user to pinch the objects. When you pinch near an object, it attaches to your hand, simulating a pinched hold. -
Throwing Mechanics:
While pinching and moving the object, the system continuously tracks acceleration, accumulating data over the time you hold it. When you release the pinch, the final throw velocity is a combination of:- The object’s accumulated acceleration during the hold.
- The hand’s velocity at the moment of release.
By blending these factors, you get a smoother, more realistic throwing motion that accounts for the object’s buildup of speed as you swing your hand.
-
Cleanup:
After the object finishes its flight (for example, when it hits the ground and stay still), it destroys itself after some time buffer to keep the scene clean.
The Tennis Ball object is available as an .lspkg file. You can easily drag and drop it into your project to easily get started. Or just start with the TennisBallBehavior.ts script.
If you have any questions or need assistance, please don't hesitate to reach out. Our community is here to help, and you can connect with us and ask for support here. We look forward to hearing from you and are excited to assist you on your journey!
Feel free to provide improvements or suggestions or directly contributing via merge request. By sharing insights, you help everyone else build better Lenses.
